// pages/my/my.js
const app = getApp();
let Api = require('../../api/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabbarIndex: 2,
        userHeadPortrait:'',
        userName: '',
        daifukuan: "0",    //待付款
        daifahuo: "0",    //待发货
        daishouhuo: "0",    //待收货
        tuikuan: "0",        //退款
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let self = this;
        self.setData({
            userHeadPortrait: app.globalData.userInfo.avatarUrl, //用户头像
            userName: app.globalData.userInfo.nickName, //用户昵称
        })
        self.cycle();
        setInterval(function () { //3秒更新一次我的订单条数
            self.cycle();
        },3000)
    },
    /**
     * 我的订单条数
     */
    cycle: function (e) {
        let self = this;
        Api.get(app.globalData.mallDomain, {//17）我的订单条数(轮询)
            doMyOrderCount: 1,
            token: app.globalData.token,
        }).then(res => {
            if(res.data.msg == '116'){
                self.setData({
                    daifukuan: res.data.daifukuan,
                    daifahuo: res.data.daifahuo, 
                    daishouhuo: res.data.daishouhuo, 
                    tuikuan: res.data.tuikuan,  
                })
            }
        })
    },
    /**
     * 点击我的订单，消息，客服，收藏列表
     */
    clickList: function (e) {
        let self = this;
        switch(e.currentTarget.dataset.text){
            case '我的订单':
                wx.navigateTo({
                    url: '../myOrder/myOrder?tabsType=全部'
                })
                break;
            case '消息':
                wx.navigateTo({
                    url: '../message/message'
                })
                break;
            case '客服':
                console.log('客服')
                break;
            case '收藏':
                wx.navigateTo({
                    url: '../collection/collection'
                })
            break;
        }
    },
    /**
     * 点击待付款，待发货，待收货，退款
     */
    clickNavList: function (e) {
        let self = this;
        switch (e.currentTarget.dataset.text) {
            case '待付款':
                wx.navigateTo({
                    url: '../myOrder/myOrder?tabsType=待付款'
                })
                break;
            case '待发货':
                wx.navigateTo({
                    url: '../myOrder/myOrder?tabsType=待发货'
                })
                break;
            case '待收货':
                wx.navigateTo({
                    url: '../myOrder/myOrder?tabsType=待收货'
                })
                break;
            case '退款':
                wx.navigateTo({
                    url: '../myOrder/myOrder?tabsType=退款'
                })
                break;
        }
    },
})